import { ref ,readonly , watch, computed} from 'vue';
import { visitTimesApi , getVisitTimesDataAllApi , getVisitTimesDataByIdApi } from '../apis/logApi';

const KEY = 'electron_key';

export default function useVisitTimesFun() {
    const visitListRef = ref([]);
    
    const visitListReadonly = readonly(visitListRef)

    // 记录访问次数  
    const setVisitItem = async (id,typeName) => {
        await visitTimesApi(id,typeName);
    }

    // 获取所有数据
    const getVisitList = async () => {
        const {code,rows} = await getVisitTimesDataAllApi();
        if (code === 200) {
            visitListRef.value = rows;
        }
    }

    // 获取 id 对应的数据
    const getVisitItemById = async (id) => {
        const {code,data} = await getVisitTimesDataByIdApi(id);
        if (code === 200) {
            return data;
        }
    }

    return {
        visitListReadonly,
        setVisitItem,
        getVisitList,
        getVisitItemById,
       
    }
}